package org.jseda.queue;

import org.jseda.thread.ManagedThread;

public class MockWorkGenerator<T> implements ManagedThread
{
  private Queue<T> _queue = null;
  private T _workUnit = null;
  private volatile boolean _isRunning = true;
  private int _generatedUnits = 0;

  public MockWorkGenerator(Queue<T> queue, T workUnit)
  {
    _queue = queue;
    _workUnit = workUnit;
  }

  public void cancel()
  {
    _isRunning = false;
  }

  public void run()
  {
    while (_isRunning)
    {
      _queue.pushBack(_workUnit);
      ++_generatedUnits;
    }
  }

  public boolean isRunning()
  {
    return _isRunning;
  }

  public int getGeneratedUnits()
  {
    return _generatedUnits;
  }
}
